﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using GestionLinqLibData;
using IRepositories;


namespace LinqRepositories
{
    public class LinqEleveRepository : IEleveRepository
    {
        private GestionDataClassesDataContext db = new GestionDataClassesDataContext();

        #region IEleveRepository Membres

        public eleve CreateEleve(eleve EleveToCreate)
        {
            db.eleve.InsertOnSubmit(EleveToCreate);
            db.SubmitChanges();
            return EleveToCreate;
        }

        public IEnumerable<eleve> ListEleves()
        {
            return (db.eleve.ToList());
        }

        public eleve GetEleve(int num_inscri)
        {
            return db.eleve.Where(e => e.num_inscription == num_inscri).FirstOrDefault();
        }

        public eleve EditEleve(eleve eleveToEdit)
        {
            var originalEleve = GetEleve(eleveToEdit.num_inscription);

            originalEleve.nom_eleve = eleveToEdit.nom_eleve;
            originalEleve.prenom_eleve = eleveToEdit.prenom_eleve;
          
            db.SubmitChanges();
            return eleveToEdit;

        }

        public void DeleteEleve(eleve eleveToDelete)
        {
            var originalEleve = GetEleve(eleveToDelete.num_inscription);

            db.eleve.DeleteOnSubmit(originalEleve);

            db.SubmitChanges();


        }

        #endregion
    }
}
